<?php
define('ROOT_HL', str_replace('//','/',dirname(__FILE__).DIRECTORY_SEPARATOR));
include_once(ROOT_HL.'../inc/_highl_.func.php');


class Clhighlight //Clhighlight
{
	public static function StDataType($str){
	    return _highl_data_type($str);	
	}
	public static function StKeywords($str){
	    return _highl_keywords($str);	
	}
	public static function StFunctions($str){
	    return _highl_functions($str);	
	}
	public static function StVars($str){
	    return _highl_vars($str);	
	}
	public static function StTabs($str){
	    return preg_replace("/\t/","    ",$str);//tab替换		
	}
	public static function StFormatNumber($a){
		if($a<10){return "0000".$a;}	if($a<100){return "000".$a;}	
		if($a<1000){return "00".$a;}	if($a<10000){return "0".$a;}	
		if($a<100000){return "".$a;}	
	}
	public static function StMyDataType($str){
		return preg_replace(array(
		"/(^|[^a-zA-Z_0-9\-])(DT[a-zA-Z_0-9]{1,})/"),
		'\\1<font  style="color:#ff6600;font-size:18px;"><b>'.
		'\\2'.'</b></font>\\3',$str);//自定义数据类型
	}
	public static function StStrings($str){
	    return preg_replace_callback(array(
		"/(\&quot;.{0,}?\&quot;)/",
		"/(\'.{0,}?\')/"),"_highl_strings_callback",$str);	//高亮字符串
	}
	public static function StClass($str){ 
		 return preg_replace("/(^|[^a-zA-Z_<>])(C[Ll][a-zA-Z_0-9]{1,})/",
		 _mkcstr("\\1<b>\\2</b>")->Fast("#cc9900",20),$str);//高亮类
	}
	public static function StMf($str){
		return preg_replace("/(^|[^a-zA-Z_<>])([_]{0,2})".
		"(mf_|Set|Get|Mf|Mk|Format|Strips|Val|High|Add|".
		"(?:&gt;)[A-Z][a-km-z])([a-zA-Z_0-9]{0,})/"
		,"\\1<font style='color:#000;'><b>\\2\\3\\4</b></font>",$str);//高成员函数	
	}
	public static function StSt($str){
		return preg_replace("/(^|[^a-zA-Z_<>])([_]{0,2})".
		"(St[A-Z]|".
		"(?:[\:]{1})[A-Z][a-km-z])([a-zA-Z_0-9]{0,})/"
		,"\\1<font style='color:#ee9999;'><b>\\2\\3\\4</b></font>",$str);//高静态成员函数
    }
	public static function StMr($str){
		return preg_replace(
		"/(^|[^a-zA-Z_<>])([_]{0,2})(m_|mr|m[A-Z]|Fallo)([a-zA-Z_0-9]{0,})/"
		,"\\1<font style='color:#339c33;'><b>\\2\\3\\4\\5</b></font>",$str);//高成员
	}
	public static function StCMSM($retstr){
		$retstr = Clhighlight::StClass($retstr);//高这类
		$retstr = Clhighlight::StMf($retstr);
		$retstr = Clhighlight::StSt($retstr);
		return    Clhighlight::StMr($retstr);
	}
}



function _preg_($str){
	$str= preg_replace(array("/([^\$\w\"\'<>]{1}|^)(\_{1}[a-z0-9]{2}[a-zA-Z0-9\-_]{0,})/"
		,"/^(\s)*(\_{1}[a-z0-9]{2}[a-z0-9\-_]{0,})/"),"\\1<font class=\"myfunc\"><b>\\2</b></font>",$str);//高亮带_的函数
 
$str=preg_replace(array("/([^a-zA-Z0-9\._]|^)([\-]{0,1}[0-9]{1,})([^A-Z\-]{0})/","/([^a-zA-Z0-9]|^)([\.x][0-9]{1,})()/")
,"\\1-FENGEFUS-d-FENGEFUD-"."\\2"."-FENGEFUS-xd-FENGEFUD-\\3",$str);//高亮数字


    $retstr = Clhighlight::StDataType($str);	
    $retstr = Clhighlight::StKeywords($retstr);
	$retstr = Clhighlight::StFunctions($retstr);	
	
		 
	$retstr = Clhighlight::StTabs($retstr);//tab替换	
	$myfunctions='unregister_class msu_window Direct3D_Init SAFE_RELEASE';
	//		 
     	
    $retstr = Clhighlight::StVars($retstr);
	
	$retstr= Clhighlight::StStrings($retstr);	
	
	$retstr = Clhighlight::StMyDataType($retstr);
	
	$retstr = Clhighlight::StCMSM($retstr);

		$myfunctions=_str2arr($myfunctions,'/\s{1,}/');	
    $pattern_arr4=array();	
    foreach(  $myfunctions as $k=>$v  ){ 
	  $pattern_arr4[]='/([\=\s\(]|^)('.$v.')([\)\s\(])/';//0719
	//$pattern_arr4[]='/([^a-zA-Z0-9<>]|^)('.$v.')([^a-zA-Z0-9<>]|$)/';
	 }		
    $retstr= preg_replace_callback($pattern_arr4,"_preg_cb4",$retstr);		
	
	$retstr=preg_replace(array( 
	"/(-FENGEFUS-d-FENGEFUD-)([\-]?[0-9]{1,})(-FENGEFUS-xd-FENGEFUD-)/",
	"/(-FENGEFUS-d-FENGEFUD-)([\.x][0-9]{1,})(-FENGEFUS-xd-FENGEFUD-)/"
	
	),"<font style='color:#de0022'><b>\\2</b></font>",$retstr);//高亮数字ff9c00
	
	
		$retstr= preg_replace(array("/(&lt;\?php|\?&gt;|&lt;\?)/"),array("<font style='color:red;'><b>\\1</b></font>"
		,"<font style='color:red;font-size:22px;'><b>\\1</b></font>"),$retstr);	//高亮php标签
	$retstr= preg_replace(array("/([\{\}\(\)\]\[])/"),array("<font class='kh'><b>\\1</b></font>"
	,"<font style='color:red;font-size:22px;'><b>\\1</b></font>"),$retstr);	// 高亮大小括号 
	$retstr=preg_replace("/(^|[^[a-zA-Z0-9_;]|\[)([A-Z_]{2,}_{1})([^a-zA-Z_0-9]{1}|$|\])/"
	,"\\1<font style='color:#0099cc'><b>\\2</b></font>\\3",$retstr);//高亮常量
	//$retstr=preg_replace("/(^|[^[a-zA-Z0-9_;])([A-CE-Z_0-9][A-Z_0-9]{1,}_{1}[A-Z0-9_]{2,})([^a-zA-Z_0-9]{0}|$)/","\\1<font style='color:#0099cc'><b>\\2</b></font>\\3",$retstr);//高亮常量
	$retstr= preg_replace_callback(array("/(\s{0,}\/\/.{0,})[^$]/"),"_preg_cb_zhushi",$retstr);	//高亮注释
    $retstr= preg_replace("/^(\s+) /","\\1",$retstr);
	return $retstr;
}

 
function _preg_cb_zhushi($matchs){
	return  '<span style="color:#cc6600;font-size:18px;"><b><i>'.preg_replace("/<.*?>/","",$matchs[1]).'</i></b></span>';
}//f90   066


function _preg_cb4($matchs){//my func
	return  $matchs[1].'<font  style="color:#dd00dd;font-size:18px;"><b>'.$matchs[2].'</b></font>'.$matchs[3];
}//9933cc myfunctions

 




//********start 从_hl.php移过来的函数*****
function _ec($arr,$t=true){

	$i=1;
	echo '<pre><table   border="0" cellspacing="0" cellpadding="0">';
	foreach($arr as $k=>$v){
	if($t){
	echo $v;
	}else{
		if( ($i%2)==0){$bgcolor="#f0f0f0;";}else{$bgcolor="#fcfcfc;";}
			echo "<tr ><td  class='num' style='display:block;color:#999;font-size:18px;width:65px;overflow:hidden;'><b>"
			.Clhighlight::StFormatNumber($i)
			."</b></td><td style='border-color:#33cc33;width:4000px; border-left-style:solid; border-left-width:4px;".
			"height:12px; padding-left:2px;background-color:".$bgcolor."'>".$v."</td></tr>";
		}
		$i++;
	}
	echo "</table></pre>";
}

function _code_hl($path)/*_code_highlight*/
{
	$fcontarr=file($path);
	$fcontarr[0]=preg_replace("/[^\w#<>\.\s\/\x{0020}-\x{9fa5}]/u","",$fcontarr[0],3);//解决文件第一行不高亮的问题
	//$fcontarr[0]=preg_replace("/^\s{1,}/","",$fcontarr[0]);
   $fcontarr=_arr_chars_callback($fcontarr,'_preg_');
	return $fcontarr;
}
//****************************************
?>
 